package com.zhongke.DKYCboot.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhongke.DKYCboot.bean.BaseCar;
import com.zhongke.DKYCboot.mapper.BaseCarMapper;
import com.zhongke.DKYCboot.service.BaseCarService;
import com.zhongke.DKYCboot.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseCarServiceImpl implements BaseCarService {
    @Autowired
    //注入接口
    private BaseCarMapper base_carMapper;

    @Override
    //查询所有车辆信息
    public Msg selectCar() {

        List<BaseCar> list = base_carMapper.selectCar();
        return Msg.success(list);
    }

    //根据车辆品牌进行查询
    @Override
    public Msg selectCarByBrand(BaseCar baseCar) {

        Integer pageNum = baseCar.getPageNum();
        Integer pageSize = baseCar.getPageSize();
        String car_brand = baseCar.getCar_Brand();
        PageHelper.startPage(pageNum, pageSize);
        List<BaseCar> list = base_carMapper.selectCarByBrand(car_brand);
        if(list!=null){
            PageInfo<BaseCar> personPageInfo = new PageInfo<>(list);
            return Msg.success(personPageInfo);
        }else {
            return Msg.fail("失败");
        }

    }
    //模糊查询
    @Override
    public Msg selectCarByCar(BaseCar base_car) {
        List <BaseCar> list=base_carMapper.selectCarByCar(base_car);
        return Msg.success(list);
    }

    /*
     * 新增
     *
     * */
    @Override
    public Msg addBaseCar(BaseCar base_car) {
        int flag= base_carMapper.addBaseCar(base_car);
        if(flag > 0){
            return Msg.success("成功");
        }else {
            return Msg.fail("失败");
        }
    }
    /*
     * 批量删除
     *
     * */
    @Override
    public int updateBase(Integer id){
        try {
            return base_carMapper.updateBase(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 1;
    }
    /*
    *
    * 修改车辆信息
    *
    * */
    @Override
    public Msg updateBaseCar(BaseCar base_car) {
        Integer i=base_carMapper.updateBaseCar(base_car);
        if (i>0){
            return Msg.success("成功");
        }
        else {
            return Msg.fail("失败");
        }
    }


}
